package com.java.demo;

public class Qian {
    private int asd;
    private boolean flag = false;

    public synchronized void save(int m){
        if(flag){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        asd=asd+m;
        System.out.println("小明存了"+m+"余额是"+asd);
        flag=true;
        this.notify();
    }
    public synchronized void take(int m){
        if(!flag){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        asd=asd-m;
        System.out.println("小李取了"+m+"余额是"+asd);
        flag=false;
        this.notify();
    }
}
